package com.docmanage.web.controller.am;

import com.docmanage.am.domain.AmCodeSerial;
import com.docmanage.am.service.impl.AmCodeSerialService;
import com.docmanage.common.annotation.Log;
import com.docmanage.common.core.controller.BaseController;
import com.docmanage.common.core.domain.AjaxResult;
import com.docmanage.common.core.page.TableDataInfo;
import com.docmanage.common.enums.BusinessType;
import com.docmanage.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 档案编码规则Controller
 * 
 * @author pointLion
 * @date 2023-06-18
 */
@RestController
@RequestMapping("/am/amSerial")
public class AmCodeSerialController extends BaseController
{
    @Autowired
    private AmCodeSerialService amCodeSerialService;

    /**
     * 查询档案编码规则列表
     */
    @PreAuthorize("@ss.hasPermi('am:amSerial:list')")
    @GetMapping("/list")
    public TableDataInfo list(AmCodeSerial amCodeSerial)
    {
        startPage();
        List<AmCodeSerial> list = amCodeSerialService.selectAmCodeSerialList(amCodeSerial);
        return getDataTable(list);
    }

    /**
     * 导出档案编码规则列表
     */
    @PreAuthorize("@ss.hasPermi('am:amSerial:export')")
    @Log(title = "档案编码规则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AmCodeSerial amCodeSerial)
    {
        List<AmCodeSerial> list = amCodeSerialService.selectAmCodeSerialList(amCodeSerial);
        ExcelUtil<AmCodeSerial> util = new ExcelUtil<AmCodeSerial>(AmCodeSerial.class);
        util.exportExcel(response, list, "档案编码规则数据");
    }

    /**
     * 获取档案编码规则详细信息
     */
    @PreAuthorize("@ss.hasPermi('am:amSerial:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(amCodeSerialService.selectAmCodeSerialById(id));
    }

    /**
     * 新增档案编码规则
     */
    @PreAuthorize("@ss.hasPermi('am:amSerial:add')")
    @Log(title = "档案编码规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AmCodeSerial amCodeSerial)
    {
        return toAjax(amCodeSerialService.insertAmCodeSerial(amCodeSerial));
    }

    /**
     * 修改档案编码规则
     */
    @PreAuthorize("@ss.hasPermi('am:amSerial:edit')")
    @Log(title = "档案编码规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AmCodeSerial amCodeSerial)
    {
        return toAjax(amCodeSerialService.updateAmCodeSerial(amCodeSerial));
    }

    /**
     * 删除档案编码规则
     */
    @PreAuthorize("@ss.hasPermi('am:amSerial:remove')")
    @Log(title = "档案编码规则", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(amCodeSerialService.deleteAmCodeSerialByIds(ids));
    }
}
